import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart' hide Action;
import 'package:www.znpigai.teacher/utils/nav.dart';

import 'action.dart';
import 'state.dart';

Effect<SubjectState> buildEffect() {
  return combineEffects(<Object, Effect<SubjectState>>{
    SubjectAction.action: _onAction,
    SubjectAction.onClick: _onClick,
  });
}

void _onAction(Action action, Context<SubjectState> ctx) {}

void _onClick(Action action, Context<SubjectState> ctx) async {
  if (ctx.state.isSelectable) {
    Navigator.of(ctx.context).pop(ctx.state);
  } else {
    Navigator.of(ctx.context)
        .pushNamed(Nav.SUBJECT_DETAIL, arguments: ctx.state);
  }
}
